//
//  EmploymentDetailVC.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/26.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "EmploymentDetailVC.h"
#import "EmploymentDetOneCell.h"
#import "EmploymentDetTwoCell.h"
#import "EmploymentDetThreeCell.h"
#import "EmploymentDetFourCell.h"
#import "EmploymentDetFiveCell.h"
#import "EmploymentDetBottom.h"
#import "EmploymentListModel.h"

#import "SearchEmploymentVC.h"
@interface EmploymentDetailVC ()


@property (nonatomic, strong) UIView *tableFooterView;

@property (nonatomic, weak) EmploymentDetBottom *bottomView;

@property (nonatomic, strong) EmploymentListModel *model;


@end

@implementation EmploymentDetailVC


- (EmploymentDetBottom *)bottomView{
    
    if (!_bottomView) {
        
        EmploymentDetBottom *temp = (EmploymentDetBottom *)[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([EmploymentDetBottom class]) owner:nil options:nil].firstObject;
        
        CGFloat bottomViewH = IPhoneX ? 83 : 49;
        
        temp.frame = CGRectMake(0, KScreenH - bottomViewH, KScreenW, bottomViewH);
        
        _bottomView = temp;
        
        [self.view addSubview:temp];
        
    }
    
    return _bottomView;
}

- (UIView *)tableFooterView{
    
    if (!_tableFooterView) {
        
        CGFloat footerH = IPhoneX ? 93 : 59;
        _tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, footerH)];
        
        _tableFooterView.backgroundColor = viewBgGrey;
    }
    
    
    return _tableFooterView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"招聘详情";
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.groupTableView.tableFooterView = self.tableFooterView;
  
    self.groupTableView.backgroundColor = viewBgGrey;
    
    self.groupTableView.rowHeight = UITableViewAutomaticDimension;
    
    self.groupTableView.estimatedRowHeight = 100;
    
    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([EmploymentDetOneCell class]) bundle:nil] forCellReuseIdentifier:[EmploymentDetOneCell identifierStr]];

    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([EmploymentDetTwoCell class]) bundle:nil] forCellReuseIdentifier:[EmploymentDetTwoCell identifierStr]];

    
    
    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([EmploymentDetThreeCell class]) bundle:nil] forCellReuseIdentifier:[EmploymentDetThreeCell identifierStr]];
    
    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([EmploymentDetFourCell class]) bundle:nil] forCellReuseIdentifier:[EmploymentDetFourCell identifierStr]];
    
    
    [self.groupTableView registerNib:[UINib nibWithNibName:NSStringFromClass([EmploymentDetFiveCell class]) bundle:nil] forCellReuseIdentifier:[EmploymentDetFiveCell identifierStr]];

    
    
    MJWeakSelf
    self.groupTableView.mj_header = [XMGRefreshHeader headerWithRefreshingBlock:^{
        
        [weakSelf loadData];
        
     }];
    
     [weakSelf.groupTableView.mj_header beginRefreshing];
    
     self.bottomView.hidden = YES;
    
}



- (void)loadData{
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"id"] = self.IdStr;
    
    MJWeakSelf;
    [[NetworkTools shareNetworkTools]sendRequestWithHttpMethod:GET_METHOD URLPath:@"Recruit/getRecruitDetail" parameters:parameters completionHandler:^(id responseObject, NSError *error) {
        
        if (!error) {
            
                                    MYJSONSTR
//
//        [responseObject[@"data"]  propertyCode];
            

            
           weakSelf.model = [EmploymentListModel mj_objectWithKeyValues:responseObject[@"data"]];
            
            [weakSelf.groupTableView.mj_header endRefreshing];
            
            
            weakSelf.bottomView.hidden = NO;

            weakSelf.bottomView.model = weakSelf.model;
            
            
            [weakSelf.groupTableView reloadData];
            
            
        } else {
            
            [weakSelf.groupTableView.mj_header endRefreshing];
            
            [SVProgressHUD showInfoWithStatus:error.domain];
            
        }
    }];
    
    
    
}





#pragma mark - tableviewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (self.model == nil) {
        return  0;
    } else {
        return  5;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.model == nil) {
        return  0;
    } else {
        return  1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        EmploymentDetOneCell *tableCell = [tableView dequeueReusableCellWithIdentifier:[EmploymentDetOneCell identifierStr]];
        
        tableCell.model = self.model;
        
        return tableCell;
    } else if (indexPath.section == 1){
        
        EmploymentDetTwoCell *tableCell = [tableView dequeueReusableCellWithIdentifier:[EmploymentDetTwoCell identifierStr]];
        tableCell.model = self.model;

        return tableCell;
        
    }else if (indexPath.section == 2){
        
        EmploymentDetThreeCell *tableCell = [tableView dequeueReusableCellWithIdentifier:[EmploymentDetThreeCell identifierStr]];
        tableCell.model = self.model;

        return tableCell;

    }else if (indexPath.section == 3){
        
        EmploymentDetFourCell *tableCell = [tableView dequeueReusableCellWithIdentifier:[EmploymentDetFourCell identifierStr]];
        tableCell.model = self.model;

        return tableCell;
    }else{
        
        EmploymentDetFiveCell *tableCell = [tableView dequeueReusableCellWithIdentifier:[EmploymentDetFiveCell identifierStr]];
        tableCell.model = self.model;

        return tableCell;
    }
    
    
    
}




- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.00001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    
    if (section == 0) {
         return 0.00001;
    } else {
        return 12;
    }
    
  
}



- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    
    UIView *temp = [[UIView alloc]init];
    temp.backgroundColor = [UIColor whiteColor];
    return temp;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *temp = [[UIView alloc]init];
    temp.backgroundColor = viewBgGrey;
    return temp;
    
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 4) {
        
        
        SearchEmploymentVC *tempVC = [[SearchEmploymentVC alloc]init];
        
        
        tempVC.supplierID = self.model.supplier_id;
        
        tempVC.navTitle = self.model.supplier_name;
        
        [self.navigationController pushViewController:tempVC animated:YES];
    }
    
   
    
    
}


- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
   
//    [myViewModel.textView becomeFirstResponder];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
